package com.wuzuqing.android.eightdiagrams.term;

import java.util.ArrayList;
import java.util.List;

public class SolarMonth {
    public int year;
    public int month;
    public ExactDate calendar;

    public SolarMonth(int year, int month) {
        this.year = year;
        this.month = month;
        calendar = ExactDate.fromYmd(year, month, 1);
    }

    public static SolarMonth fromYm(int y, int m) {
        return new SolarMonth(y, m);
    }


    public int getYear() {
        return this.year;
    }

    public int getMonth() {
        return this.month;
    }

    public SolarMonth next(int months) {
        ExactDate date = ExactDate.fromYmd(this.year, this.month, 1);
        date.setMonth(date.getMonth() + months);
        return fromYm(date.getYear(), date.getMonth());
    }

    public List<Solar> getDays() {
        List<Solar> l = new ArrayList<>();
        Solar d = Solar.fromYmd(this.year, this.month, 1);
        l.add(d);
        int days = SolarUtil.getDaysOfMonth(this.year, this.month);
        for (int i = 1; i < days; i++) {
            l.add(d.next(i,false));
        }
        return l;
    }

    public List<SolarWeek> getWeeks(int start) {
        List<SolarWeek> l = new ArrayList<>();
        int weeks = SolarUtil.getWeeksOfMonth(this.year, this.month, start);
        for (int i = 0; i < weeks; i++) {
            l.add(SolarWeek.fromYmd(this.year, this.month, 1 + i * 7, start));
        }
        return l;
    }

    @Override
    public String toString() {
        return this.getYear() + "- " + this.getMonth();
    }

    public String toFullString() {
        return this.getYear() + "年 " + this.getMonth() + "月 ";
    }
}